﻿using BLL;
using Function;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using System.Data;

namespace UI
{
    public partial class MainWeb : System.Web.UI.Page
    {
        public List<ShopEarning> list = null;
        MessageBox box = new MessageBox();
        protected string _strMess;
        protected void Page_Load(object sender, EventArgs e)
        {
            ST_InvestorBLL bll = new ST_InvestorBLL();
            ST_Investor model = bll.GetModel(Method.CurrentUserID);
            if (model.LoginPWChanged == 1)
            {
                //box.ErrorBox(this, "您还未修改过登录密码，为了您的账户安全，请尽快修改登录密码！");
                MessageBox_Page McBx = new MessageBox_Page();//实例化对话框
                string RemarkString;
                RemarkString = "您还未修改过登录密码，为了您的账户安全，请尽快修改登录密码！";

                McBx.Title = "系统提示";
                McBx.AddContent(RemarkString);
                McBx.Type = MsgType.Error;
                McBx.AddUrl("立即修改", "../Module/User/ChangePasswd.aspx", UrlType.Href);
                MessageEvent.MessageBox(McBx, "ErrorPage/ShowMsg.aspx");
            }

            ST_InvestorMore moremodel = new ST_InvestorMoreBLL().GetModel(Method.CurrentUserID);
            if (moremodel == null)
            {
                MessageBox_Page McBx = new MessageBox_Page();//实例化对话框
                string RemarkString;
                RemarkString = "未找到对象";

                McBx.Title = "系统提示";
                McBx.AddContent(RemarkString);
                McBx.Type = MsgType.Error;
                McBx.AddUrl("返回", "../../Module/User/UserMsge.aspx", UrlType.Href);
                MessageEvent.MessageBox(McBx, "../../ErrorPage/ShowMsg.aspx");
            }
            if (moremodel.GetCoinPwChanged == 1)
            {
                div_getCoinPwd.Attributes.CssStyle.Add("display", "block");
            }
            //账户余额
            lblCoin_GetedCoin.Text = (moremodel.Coin + moremodel.GetedCoin).ToString();
            lblcoin1.Text = moremodel.Coin.ToString();
            lblgetedcoin1.Text = moremodel.GetedCoin.ToString();
            //总收益
            lblALLCoin.Text = moremodel.AllCoin.ToString();
            //可提现
            lblCoin.Text = moremodel.Coin.ToString();
            //正在提现
            lblGetedCoin.Text = moremodel.GetedCoin.ToString();
            //已提现
            lblAllCutCoin.Text = moremodel.AllCutCoin.ToString();

            list = new List<ShopEarning>();
            //投资者下的门店列表信息
            string shopID = "";
            DataSet shoplist = new GX_InvestorShopBLL().GetList("InvestorID=" + Method.CurrentUserID);

            if (shoplist.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow item in shoplist.Tables[0].Rows)
                {
                    ShopEarning Emodel = new ShopEarning();
                    //年销量与收益
                    DataTable ds = bll.Get_sy(item["ShopID"].ToInt32(),DateTime.Now,out  _strMess);

                    Emodel.Id = item["ShopID"].ToInt32();
                    Emodel.ShopName = new ST_ShopBLL().GetModel(item["ShopID"].ToInt32()).STitle ;

                    if (ds.Rows.Count > 0)
                    {
                        for (int i = 0; i < ds.Rows.Count; i++)
                        {
                            if (ds.Rows[i]["Num"].ToString()=="0")
                            {
                                Emodel.Rsy = String.Format("{0:F}",ds.Rows[i]["InCome"]);
                                Emodel.Rje = String.Format("{0:F}",ds.Rows[i]["AllOrderMoney"]);
                            }
                            if (ds.Rows[i]["Num"].ToString() == "1")
                            {
                                Emodel.Ysy = String.Format("{0:F}",ds.Rows[i]["InCome"]);
                                Emodel.Yje = String.Format("{0:F}",ds.Rows[i]["AllOrderMoney"]);
                            }
                            if (ds.Rows[i]["Num"].ToString() == "2")
                            {
                                Emodel.Nsy = String.Format("{0:F}",ds.Rows[i]["InCome"]);
                                Emodel.Nje = String.Format("{0:F}",ds.Rows[i]["AllOrderMoney"]);
                            }
                        }
                    }
                    else {
                        Emodel.Nsy = "0.00";
                        Emodel.Ysy = "0.00";
                        Emodel.Rsy = "0.00";

                        Emodel.Nje = "0.00";
                        Emodel.Yje = "0.00";
                        Emodel.Rje = "0.00";
                    }
                    list.Add(Emodel);
                }
            }
        }
    }
}